﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Data.EntityFramework
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class EntityObjectQuery<TEntity> : EntityDataCommand<TEntity>, IObjectQuery<TEntity> where TEntity : class
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public EntityObjectQuery(DbContext context) : base(context)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public virtual TEntity Execute(Expression<Func<TEntity, bool>> expression)
        {
            IQueryable<TEntity> queryable = CurrentDbContext.Set<TEntity>();
            return queryable.SingleOrDefault(expression);
        }
    }
}
